/*
 * gbdt_feature.h
 *
 *  Created on: 2012-7-21
 *      Author: wanghaox
 */

#ifndef GBDT_FEATURE_H_
#define GBDT_FEATURE_H_

#include <math.h>
#include <string.h>
#include <algorithm>
#include <ostream>
#include <stdlib.h>
#include <math.h>
#include "gbdt.h"

using namespace std;

class GbdtUpdater;
class GbdtTree;

class GbdtFeature { // represents a training data set distributed among processors feature-wise
public:
	// constructor/destructor
	GbdtFeature();
	~GbdtFeature();

	bool init(int instance_num, int feature_index);
	// reading and initialization
//	void initMetrics();
	void sort();

	void set(int instance, float value);

	void reset_instance_node();

	// prediction
//    void updatePred(int i, double p);
//    void updateResiduals();

private:
	friend class GbdtUpdater;
	friend class GbdtTree;

	int _global_feature_index;
	int _instance_num;

	double *_raw_features;	// feature values ordered by instance
	double *_sored_feature;	// feature values ordered by value
	int *_sorted_instance;	//  indices of original instances for each sorted feature

	int* _instance_to_treenode; // last node reached in tree, permits constant time classification at each level

	void sort_instance_by_value();	// sort instance by feature value

	///////////////////////////////////////////
	// dataset descriptors
//	int N; // number of data instances
//    int numfeatures; // number of features stored on this processor
//    bool isrankingset; // whether qids should be expected in file, also whether to compute ranking metrics
	// int minfeature, maxfeature; // range of feature indices on this processor; mapped from [minf,maxf] to [1,numf]; 0 feature for convenience
//    int myid, numprocs;
//    int numqueries; // number of queries in the data set

	// static attributes
//    int* qid; // query id of each instance
//    float** rawfeatures; // feature values ordered by instance
//    float** sortedfeatures; // feature values ordered by value
//    int** sortedindices; // indices of original instances for each sorted feature
//    double* label; // target label value of each instance

	// level-specific attributes
//	int* node; // last node reached in tree, permits constant time classification at each level

	// prediction attributes
//	double* pred; // current cumulative prediction for each instance
//	double* residual;  // current cumulative residual for each instance

	// metric attributes
//	double* idealdcg; // ideal dcg by query

	// methods
//	bool processLine(int &linenum, ifstream &input, int i);
//    bool parseFeatureValue(string &cfeature, string &cvalue);
//	int computeNumFeatures(int nf, int numprocs, int myid);
};

#endif /* GBDT_FEATURE_H_ */
